<?php
/**
 * 动作类基类
 */

#加载过滤类
require_once ACTION_PATH.'common/filter.class.php';
#加载缓存类
require_once ACTION_PATH.'common/cache.class.php';


abstract class ActionBase1 {
	protected $_error = '';
	
	protected $template = '';
	
	protected  $data;
	
	
	public final function __construct ( ) {
		session_start();
		
		$method = isset ( $_REQUEST['method'] ) ? $_REQUEST['method'] : 'action';
		unset($_REQUEST['path']);
		unset($_REQUEST['action']);
		unset($_REQUEST['method']);
		$_REQUEST['_data'] = file_get_contents("php://input");	
		$this->data['request'] = $_REQUEST;
		
		
		$this->init();
		//获取分页
		#$this->data['page']=(isset ( $this->data ['page'] )) ? ($this->data ['page'] - 1) : 0;
		
		
		
		unset($_REQUEST);
		unset($_GET);
		unset($_POST);
		/*dump($this->data);exit; */
		#dump($this->data['request']);
		
		if(!isset($this->data ['request']['HASH_CODE'])){
			$this->data['formhash']=filter::formhash();
		}
		
		$this -> $method ( );
		
	}
	
	public final function  __destruct(){
		/* $request = $this->data['request'];
		unset($this->data);
		$this->data['request']=$request; */
	}
	
	/**
	 * initialization初始化方法
	 * 因为父类的构造函数，__construct已经被设置为final类，所以子类不能重写__construct构造函数。所以在父类中加一个初始化类，子类重写该方法，会在父类的构造函数中被执行
	 */
	 public function init(){
	 	
	 	
	 }
	
	public function __call ( $name, $arguments ) {
		$this -> action ( );
	}
	
	public function template($temname){
		
		//声明模板
		$this->template = load_libra('smarty');
		
		
		$this->template->assign ( $this->data );
		$this->template->display ( $temname );
	}
	
	protected function request($url){
		get_url_content($url);
	}
	
	/**
	 * 实际请求动作执行方法
	 * @date 2012/11/29
	 */
	abstract public function action (   );
	
	
}
